package com.example.sql_2_code_demo.service.impl;

import com.example.sql_2_code_demo.entity.OrderPaySetting;
import com.example.sql_2_code_demo.dao.OrderPaySettingDao;
import com.example.sql_2_code_demo.service.OrderPaySettingService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 支付设置(OrderPaySetting)表服务实现类
 *
 * @author makejava
 * @since 2022-10-09 10:01:37
 */
@Service("orderPaySettingService")
public class OrderPaySettingServiceImpl implements OrderPaySettingService {
    @Resource
    private OrderPaySettingDao orderPaySettingDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public OrderPaySetting queryById(Long id) {
        return this.orderPaySettingDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param orderPaySetting 筛选条件
     * @param pageRequest     分页对象
     * @return 查询结果
     */
    @Override
    public Page<OrderPaySetting> queryByPage(OrderPaySetting orderPaySetting, PageRequest pageRequest) {
        long total = this.orderPaySettingDao.count(orderPaySetting);
        return new PageImpl<>(this.orderPaySettingDao.queryAllByLimit(orderPaySetting, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param orderPaySetting 实例对象
     * @return 实例对象
     */
    @Override
    public OrderPaySetting insert(OrderPaySetting orderPaySetting) {
        this.orderPaySettingDao.insert(orderPaySetting);
        return orderPaySetting;
    }

    /**
     * 修改数据
     *
     * @param orderPaySetting 实例对象
     * @return 实例对象
     */
    @Override
    public OrderPaySetting update(OrderPaySetting orderPaySetting) {
        this.orderPaySettingDao.update(orderPaySetting);
        return this.queryById(orderPaySetting.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.orderPaySettingDao.deleteById(id) > 0;
    }
}
